package com.wibo.account;

import java.util.ArrayList;

import com.wibo.common.CommentItem;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class CommentListItemAdapter extends BaseAdapter {
	
	private Context mContext;
	private ArrayList<CommentItem> mCommentItemData;
	
	public CommentListItemAdapter(Context mContext) {
		super();
		this.mContext = mContext;
	}

	public CommentListItemAdapter(Context mContext,
			ArrayList<CommentItem> mCommentItemData) {
		super();
		this.mContext = mContext;
		this.mCommentItemData = mCommentItemData;
	}
	
	public void setAdapterData(ArrayList<CommentItem> mCommentItemData){
	    this.mCommentItemData = mCommentItemData;
	}
	
	public ArrayList<CommentItem> getAdapterData(){
		return this.mCommentItemData;
	}

	@Override
	public int getCount() {
		if( mCommentItemData == null ){
			return 0;
		}
		return mCommentItemData.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mCommentItemData.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		if (mCommentItemData == null) {
			return null;
		}
		if (arg1 == null) {
			CommentListItemView itemView = null;

			itemView = new CommentListItemView(mContext);

			itemView.updateView(mCommentItemData.get(arg0), String
					.valueOf(arg0));
			arg1 = itemView;
		} else {
			((CommentListItemView) arg1).updateView(mCommentItemData.get(arg0), String.valueOf(arg0));
		}
		return arg1;
	}

}
